/********************************************************
 *
 * FILE NAME:   smartingeegrecord.h
 *
 * DESCRIPTION:
 *  Module with Smarting EEG output file
 *
 ********************************************************/

#ifndef SMARTINGEEGRECORD_H
#define SMARTINGEEGRECORD_H

/********************************************************/
/*              Includes                                */
/********************************************************/
#include "signalprocessing.h"

#include <QObject>
#include <QMutex>
#include <QFile>

/********************************************************/
/*              Defines                                 */
/********************************************************/
#define SMARTINGEEGRECORD__NUM_OF_CHANNELS 29

/********************************************************/
/*              Macros                                  */
/********************************************************/

/********************************************************/
/*              Typedefs                                */
/********************************************************/
class SmartingEEGRecord;
class SmartingEEGRecordWorker;

class SmartingEEGRecord : public QObject
{
    Q_OBJECT

    friend class SmartingEEGRecordWorker;

    /********************************************************/
    /*              Typedefs                                */
    /********************************************************/
    public:

    protected:

    private:

    /********************************************************/
    /*              Functions Declarations                  */
    /********************************************************/
    public:
        /********************************************************
         * Function Name    :   SmartingEEGRecord
         *
         * Description      :   Constructor
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :   QObject *parent = Qt Object parent of the SmartingEEGRecord object
         *
         * Returns      	:
         *
         * Reviewed by      :   v_duschan@hotmail.com
         *
         ********************************************************/
        SmartingEEGRecord(QObject *parent = 0);

        ~SmartingEEGRecord();

        /********************************************************
         * Function Name    :   registerTypes
         *
         * Description      :   Register SmartingEEGRecord class to QML
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns      	:
         *
         * Reviewed by      :   v_duschan@hotmail.com
         *
         ********************************************************/
        static void registerTypes(const char *uri);

        Q_INVOKABLE bool init(int burstLength);

        Q_INVOKABLE void start();

        Q_INVOKABLE void closeRecord();
        Q_INVOKABLE bool newRecord(const QString &dir, const QString &description);

        Q_INVOKABLE EXPORT_SIGNAL(_inISig[0], Channel0ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[1], Channel1ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[2], Channel2ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[3], Channel3ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[4], Channel4ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[5], Channel5ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[6], Channel6ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[7], Channel7ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[8], Channel8ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[9], Channel9ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[10], Channel10ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[11], Channel11ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[12], Channel12ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[13], Channel13ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[14], Channel14ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[15], Channel15ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[16], Channel16ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[17], Channel17ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[18], Channel18ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[19], Channel19ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[20], Channel20ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[21], Channel21ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[22], Channel22ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[23], Channel23ISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[24], SyncISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[25], GyroXISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[26], GyroYISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[27], GyroZISignal)
        Q_INVOKABLE EXPORT_SIGNAL(_inISig[28], BatteryISignal)

    public slots:

    protected:

    protected slots:

    private:

    private slots:

    /********************************************************/
    /*              Variables Declarations                  */
    /********************************************************/
    public:

    protected:

    private:
        QThread *_workerThread;
        SmartingEEGRecordWorker *_worker;

        int _maxBurstLength;

        ISignal *_inISig[SMARTINGEEGRECORD__NUM_OF_CHANNELS];

        QFile *_file;
        QMutex *_fileMtx;
};
class SmartingEEGRecordWorker : public QObject
{
    Q_OBJECT

    friend class SmartingEEGRecord;

    /********************************************************/
    /*              Typedefs                                */
    /********************************************************/
    public:

    protected:

    private:

    /********************************************************/
    /*              Functions Declarations                  */
    /********************************************************/
    public:
        /********************************************************
         * Function Name    :   SmartingEEGRecordWorker
         *
         * Description      :   Constructor
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns      	:
         *
         * Reviewed by      :   v_duschan@hotmail.com
         *
         ********************************************************/
        SmartingEEGRecordWorker(SmartingEEGRecord &context);

    public slots:

    protected:

    protected slots:

    private:

    private slots:
        void _startRecording();

    /********************************************************/
    /*              Variables Declarations                  */
    /********************************************************/
    public:

    protected:

    private:
        SmartingEEGRecord &_context;
};

/********************************************************/
/*              Functions Declarations                  */
/********************************************************/

/********************************************************/
/*              Variables Declarations (IMPORT)         */
/********************************************************/

#endif /* SMARTINGEEGRECORD_H */
